package com.zretc.emptraining.serviceimpl;

import java.util.List;

import com.zretc.emptraining.dao.DeptDao;
import com.zretc.emptraining.daoimpl.DeptDaoImpl;
import com.zretc.emptraining.dbtools.PageData;
import com.zretc.emptraining.entity.Dept;
import com.zretc.emptraining.service.DeptService;

public class DeptServiceImpl implements DeptService {
	DeptDao deptimpl = new DeptDaoImpl();
	@Override
	public boolean addDept(Dept dept) {
		if(dept == null) {
			return false;
		}
		return deptimpl.addDept(dept);
	}
	
	@Override
	public boolean addDeptNoManager(Dept dept) {
		if(dept == null) {
			return false;
		}
		return deptimpl.addDeptNoManager(dept);
	}
	
	@Override
	public boolean existDeptName(String deptname) {
		Dept d = deptimpl.getDeptByDeptName(deptname);
		if(d != null) {
			return false;
		}
		return true;
	}
	
	@Override
	public boolean delDept(int deptno) {
		if(deptno > 0) {
			return deptimpl.delDeptByDeptNo(deptno);
		}
		return false;
	}
	
	// 这里的判断要判断 1.部门名是否存在？ 2.主管是否存在？    部门名唯一 + 主管唯一
	@Override
	public boolean updDept(Dept dept) {
		
		if(dept != null) {
			return deptimpl.updDept(dept);
		}
		
		return false;
	}

	@Override
	public PageData<Dept> getPageByDeptName(int page, int pageSize, String keyword) {
		if(page < 1) {
			page = 1;
		}
		return deptimpl.getPageByDeptName(page, pageSize, keyword);
	}
	
	@Override
	public List<Dept> getAllDept(String key) {
		// TODO Auto-generated method stub
		return deptimpl.getAllDept(key);
	}
	
	@Override
	public String getDeptnameByDeptno(int deptno) {
		Dept dept = deptimpl.getDeptByDeptNo(deptno);
		return dept.getDeptName();
	}

	@Override
	public int getDeptnoByDeptname(String deptname) {
		Dept dept = deptimpl.getDeptByDeptName(deptname);
		int deptNo = dept.getDeptNo();
		return deptNo;
	}
}
